<?php
include "config.php";
$result = mysql_query("SELECT * FROM `sama`");

while ($row = mysql_fetch_object($result)) {
    $idl = $row->id1;
	$idt = $row->id2;
	
	$result1 = mysql_query("SELECT * FROM `jarak` where id1 = $idl");
	while ($row = mysql_fetch_object($result1)) {
	$jarak1 = $row->jarak;
	$id2 = $row->id2;
	$query1 = "INSERT INTO jarak (id1, id2, jarak) VALUES ($idt, $id2, $jarak1)";
	$add = mysql_query($query1);
	}
	
	$result2 = mysql_query("SELECT * FROM `jarak` where id2 = $idl");
	while ($row = mysql_fetch_object($result2)) {
	$jarak2 = $row->jarak;
	$id1 = $row->id1;
	$query2 = "INSERT INTO jarak (id1, id2, jarak) VALUES ($id1, $idt, $jarak1)";
	$add = mysql_query($query2);
	}
	
	$result3 = mysql_query("SELECT * FROM `jarak` where id2 = $idt");
	while ($row = mysql_fetch_object($result3)) {
	$jarak3 = $row->jarak;
	$id1 = $row->id1;
	$query3 = "INSERT INTO jarak (id1, id2, jarak) VALUES ($id1, $idl, $jarak3)";
	$add = mysql_query($query3);
	}
	
	$result4 = mysql_query("SELECT * FROM `jarak` where id1 = $idt");
	while ($row = mysql_fetch_object($result4)) {
	$jarak4 = $row->jarak;
	$id2 = $row->id2;
	$query4 = "INSERT INTO jarak (id1, id2, jarak) VALUES ($idl, $id2, $jarak4)";
	$add = mysql_query($query4);
	}
	
}




  

?> 